home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5844 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: hex to dec function?
  5. Date: 21 Feb 96 13:34:09 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.824909649@rscernix>
  8. References: <4gdh1b$bg@mailhost.mwmicro.com> <4gdolr$ha9@madeline.INS.CWRU.Edu>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4gdolr$ha9@madeline.INS.CWRU.Edu> mab22@po.CWRU.Edu (Michael A. Balfour) writes:
  13.  
  14.  
  15. >In a previous article, aschlies@citynet.net () says:
  16. >
  17. >>Hi There,
  18. >>
  19. >>Is there a function that converts HEX to Dec in ANSI C?
  20. >>
  21. >You could try sscanf.  For example:
  22. >
  23. >main()
  24. >{
  25. >  char hex[9];
  26. >  int dec;
  27. >
  28. >  strcpy(hex,"FFFF");
  29. >  sscanf(hex,"%xd",&dec);
  30.                  ^
  31. What's the purpose of this 'd'?
  32.  
  33. It's advisable to pass a pointer to unsigned int when using %x in scanf.
  34. Otherwise you violate a "shall" in the standard, invoking undefined
  35. behaviour.
  36.  
  37. >}
  38.  
  39. BTW, strtol will work for any base in the 2..36 range.
  40.  
  41. Dan
  42. --
  43. Dan Pop
  44. CERN, CN Division
  45. Email: danpop@mail.cern.ch 
  46. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  47.